<?php
/*
	$strSiteCSS = "shop.css";	
	if(defined('HOST'))
	{
		if(file_exists("./cms".HOST.".css"))
			$strSiteCSS = "cms".HOST.".css";
	}
*/
	//set image paths the call routine to list jpgs within the chosen directory
	$strThumbPath 		= "./images/product/thumbz/";
	$strDefaultPath 	= "./images/product/";
	$strLargeDirectory	= "./images/product/large/";
	$txtUnitsInStock 	= 1;
	$txtQuantityPerUnit = 1;
	$txtProduct 		= null;
	$txtDescription 	= null;
	$txtExtraDescription = null;
	$txtDisplayOrder 	= null;
	$txtMetaTitle 		= null;
	$txtMetaDescription = null;
	$txtMetaKeyword 	= null;
    $txtMetaComment 	= null;
    $cboCategory 		= null;
    $cboWeight			= null;
    $txtOwnProductCode	= null;
    $txtBarcode			= null;
    $cboSupplier 		= null;
    $txtSupplierProductID = null;
?>


<script language="javascript" type="text/javascript" src="/vendere-jscript/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
<script language="javascript" type="text/javascript">
tinyMCE.init({
	theme : "advanced",
	ask : false,
	plugins : "table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,zoom,flash,searchreplace,print,contextmenu",
	theme_advanced_buttons1_add_before : "save,separator",
	theme_advanced_buttons1_add : "fontselect,fontsizeselect",
	theme_advanced_buttons2_add : "separator,insertdate,inserttime,preview,zoom,separator,forecolor,backcolor",
	theme_advanced_buttons2_add_before: "cut,copy,paste,separator,search,replace,separator",
	theme_advanced_buttons3_add_before : "tablecontrols,separator",
	theme_advanced_buttons3_add : "emotions,iespell,flash,advhr,separator,print",
	theme_advanced_toolbar_location : "top",
	theme_advanced_toolbar_align : "left",
	theme_advanced_path_location : "bottom",
	theme_advanced_resizing : true,
	// Example content CSS (should be your site CSS)
	content_css : "<?php echo $strSiteCSS;?>",
	plugin_insertdate_dateFormat : "%Y-%m-%d",
	plugin_insertdate_timeFormat : "%H:%M:%S",
	extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
	spellchecker_languages : "+English=en,Danish=da,Dutch=nl,Finnish=fi,French=fr,German=de,Italian=it,Polish=pl,Portuguese=pt,Spanish=es,Swedish=sv"
	
});

function toggleEditor(id) {
	var elm = document.getElementById(id);

	if (tinyMCE.getInstanceById(id) == null)
		tinyMCE.execCommand('mceAddControl', false, id);
	else
		tinyMCE.execCommand('mceRemoveControl', false, id);
}

window.onload = toggleEditor('txtDescription');
window.onload = toggleEditor('txtExtraDescription');
</script>

<?php

$strScreenName = 'EnterProduct';
$strQueryName = 'qryAddProduct';
$strFormName = 'frmEnterProduct';

     if ((isset($_REQUEST['intProductID'])) && (!isset($_REQUEST['strReprocessing']))) 
     {
             include (MODULE . "/action/qrySelectProduct");
			 $strButtonTitle = "update";
			 $strFormTitle = "Update ".$myrow["Product"];
             $cboID = stripslashes($myrow["ID"]);
             $txtProduct = stripslashes(eregi_replace('\"', "&quot;", $myrow["Product"]));
             $txtDescription = stripslashes(eregi_replace('\"', "&quot;", $myrow["Description"]));
             $txtExtraDescription = stripslashes(eregi_replace('\"', "&quot;", $myrow["ExtraDescription"]));
             $cboWeight = stripslashes($myrow["Weight"]);
             $txtOwnProductCode = stripslashes($myrow["OwnProductCode"]);
             $txtBarcode = stripslashes($myrow["Barcode"]);
             $cboSupplier = stripslashes($myrow["Supplier"]);
             $txtSupplierProductID = stripslashes($myrow["SupplierProductID"]);
             $cboCategory = stripslashes($myrow["Category"]);
             $txtQuantityPerUnit = stripslashes($myrow["QuantityPerUnit"]);
			 $txtCostPrice = stripslashes($myrow["CostPrice"]);
             $txtUnitPrice = stripslashes($myrow["UnitPrice"]);
			 $txtFullPrice = stripslashes($myrow["FullPrice"]);
             $cboVatRate = stripslashes($myrow["VatRate"]);
             $txtUnitsInStock = stripslashes($myrow["UnitsInStock"]);
			 $chkDiscontinued = stripslashes($myrow["Discontinued"]);
             $txtUnitsOnOrder = stripslashes($myrow["UnitsOnOrder"]);
             $txtReorderLevel = stripslashes($myrow["ReorderLevel"]);
             $txtUploadedPicture = stripslashes($myrow["UploadedPicture"]);
			 $chkPromotionalItem = stripslashes($myrow["PromotionalItem"]);
			 $txtMetaTitle = stripslashes($myrow["MetaTitle"]);
             $txtMetaDescription = stripslashes($myrow["MetaDescription"]);
             $txtMetaKeyword = stripslashes($myrow["MetaKeyword"]);
             $txtMetaComment = stripslashes($myrow["MetaComment"]);	 
			 $txtDisplayOrder = stripslashes($myrow["DisplayOrder"]);
         }else{
			if(isset($_REQUEST['intProductID']))
         		$intProductID = cleanFormInput($_REQUEST['intProductID']);
         	else 
         		$intProductID = null;
         		
		 	//$cboVatRate = 2;
		 	$strFormTitle = "Enter New Product";
			$strButtonTitle 		= "save";
			if(isset($_REQUEST['txtSupplierProductID']))
				$txtSupplierProductID = cleanFormInput($_REQUEST['txtSupplierProductID']);
				
			if(isset($_REQUEST['cboSupplier']))
				$cboSupplier = cleanFormInput($_REQUEST['cboSupplier']);
			 
			if(isset($_REQUEST['txtBarcode']))
				$txtBarcode = cleanFormInput($_REQUEST['txtBarcode']);
				
			if(isset($_REQUEST['txtOwnProductCode']))
				$txtOwnProductCode = cleanFormInput($_REQUEST['txtOwnProductCode']);
				
			if(isset($_REQUEST['cboWeight']))	
				$cboWeight = cleanFormInput($_REQUEST['cboWeight']);
			
			if(isset($_REQUEST['cboCategory']))	
				$cboCategory = cleanFormInput($_REQUEST['cboCategory']);
				
			if(isset($_REQUEST['txtUnitsInStock']))	
				$txtUnitsInStock = $_REQUEST['txtUnitsInStock'];	

			if(isset($_REQUEST['txtQuantityPerUnit']))
				$txtQuantityPerUnit	= $_REQUEST['txtQuantityPerUnit'];
			
			if(isset($_REQUEST['txtProduct']))
				$txtProduct = cleanFormInput($_REQUEST['txtProduct']);
				
			if(isset($_REQUEST['txtDescription']))
				$txtDescription = cleanFormInput($_REQUEST['txtDescription']);
				
            if(isset($_REQUEST['txtExtraDescription']))
				$txtExtraDescription = cleanFormInput($_REQUEST['txtExtraDescription']);
				
			if(isset($_REQUEST['txtMetaTitle']))
				$txtMetaTitle = cleanFormInput($_REQUEST['txtMetaTitle']);
				
			if(isset($_REQUEST['txtMetaDescription']))
				$txtMetaDescription = cleanFormInput($_REQUEST['txtMetaDescription']);

            if(isset($_REQUEST['txtMetaKeyword']))
				$txtMetaKeyword = cleanFormInput($_REQUEST['txtMetaKeyword']);
				
            if(isset($_REQUEST['txtMetaComment']))
				$txtMetaComment = cleanFormInput($_REQUEST['txtMetaComment']);
				
            if(isset($_REQUEST['txtDisplayOrder']))
				$txtDisplayOrder = cleanFormInput($_REQUEST['txtDisplayOrder']);

		}
if($strStyleSheet == TRUE){
	echo "<table class='Normal' border='0' align='left' width='100%' bgcolor='white'>";
}
else
{
	echo "<!-- strStyleSheet = $strStyleSheet -->";			 
}

echo "
<tr>
     <td>
         <table  width='648' cellpadding='0' cellspacing='0' border='0' class='Normal' align='center'>
     <tr align=\"right\">
         <td align='left' colspan='2'>
             <h2>$strFormTitle</h2>
         </td>
     </tr>
";?>
	
<?php
echo (StartForm($strScreenName, "post", $strQueryName,array('intProductID'=>$intProductID,'strReprocessing'=>'True'),"","multipart/form-data",$strFormName,"","return frmEnterProduct_onsubmit()"));

echo "
     <tr>
         <td align=\"right\" colspan='2'>
             <input type='image' src='./images".SITE_SUFFIX."/$strButtonTitle.gif' alt='$strButtonTitle'>
         </td>
     </tr>

     <tr>
         <td align='left' colspan='2'>
             <b>Product Name :&nbsp;</b>
             <input type=\"text\" name=\"txtProduct\" value = \"$txtProduct\" size= \"85\" maxlength=\"100\">
         </td>
     </tr>

     <tr  align=\"right\">
         <td align='left' colspan='2'>
             <b>Description :</b><br/>
             <a href=\"javascript:toggleEditor('txtDescription');\">Add/Remove editor</a><br />
             <textarea id='txtDescription' cols=100 rows=15 name=\"txtDescription\">$txtDescription</textarea>
         </td>
     </tr>

	<tr  align=\"right\">
         <td align='left' colspan='2'>
             <b>Additional Description :</b><br/>
             <a href=\"javascript:toggleEditor('txtExtraDescription');\">Add/Remove editor</a><br />
             <textarea id='txtExtraDescription' cols=100 rows=15 name=\"txtExtraDescription\">$txtExtraDescription</textarea>
         </td>
     </tr>

	<tr>
		<td colspan='2'>
			<hr/>
		</td>
	 </tr>

     <tr>
         <td align='left' colspan='2'>
             <b>Meta Title :&nbsp;</b>
             <input type=\"text\" name=\"txtMetaTitle\" value = \"$txtMetaTitle\" size= \"89\" maxlength=\"65\">
         </td>
     </tr>

     <tr>
         <td align='left' colspan='2'>
             <b>Meta Description :&nbsp;</b><br/>
             <textarea cols=100 rows=3 name=\"txtMetaDescription\">$txtMetaDescription</textarea>
         </td>
     </tr>

     <tr  align='left'>
         <td align='left' colspan='2'>
             <b>Meta Keyword :</b>
			 <input type=\"text\" name=\"txtMetaKeyword\" value = \"$txtMetaKeyword\" size= \"85\" maxlength=\"300\">
         </td>
     </tr> 

	 <tr>
         <td align='left' colspan='2'>
             <b>Meta Comment :&nbsp;</b>
             <input type=\"text\" name=\"txtMetaComment\" value = \"$txtMetaComment\" size= \"63\" maxlength=\"200\">
         </td>
     </tr>

	 <tr>
		<td colspan='2'>
			<hr/>
		</td>
	 </tr>

     <tr align=\"right\">
         <td align=\"right\">
             <b>Category :&nbsp;</b>
         </td>
         <td align=\"left\">";
             CreateDropDown("cboCategory", "SELECT * FROM tblCategory ORDER BY 2", "", $cboCategory);
echo "
             <a href='".ScreenURL("EnterCategory")."' target='_blank'>+</a>
         </td>
     </tr>
	 
	 <tr>
         <td align='right'>
             <b>Order to display in Product screens :&nbsp;</b>
         </td>
         <td align=\"left\">
             <input type=\"text\" name=\"txtDisplayOrder\" value = \"$txtDisplayOrder\" size= \"7\" maxlength=\"7\"></div>
         </td>
     </tr>
	 
     <tr>
         <td align=\"right\">
             <b>Weight (kg) :&nbsp;</b>
         </td>
         <td align=\"left\">
		 	<input type=\"text\" name=\"cboWeight\" value = '$cboWeight' size= \"8\" maxlength=\"15\">
         </td>
     </tr>

     <tr>
         <td align=\"right\">
             <b>Own Product Code :&nbsp;</b>
		 </td>
		 <td align=\"left\">
             <input type=\"text\" name=\"txtOwnProductCode\" value = \"$txtOwnProductCode\" size= \"30\" maxlength=\"50\">
         </td>
     </tr>

      <tr>
         <td align=\"right\">
             <b>Bar Code :&nbsp;</b>
         </td>
         <td align=\"left\">
           <input type=\"text\" name=\"txtBarcode\" value = \"$txtBarcode\" size= \"16\" maxlength=\"16\">
         </td>
     </tr> 

     <tr align=\"right\">
         <td align=\"right\">
             <b>Supplier :&nbsp;</b>
         </td>
         <td align=\"left\">";
             CreateDropDown("cboSupplier", "SELECT * FROM tblSupplier ORDER BY 2", "", $cboSupplier);
echo "
             <a href='".ScreenURL("EnterSupplier")."' target='_blank'>+</a>
         </td>
     </tr>

     <tr>
         <td align=\"right\">
             <b>Supplier Code :&nbsp;</b>
		 </td>
		 <td  align=\"left\">
             <input type=\"text\" name=\"txtSupplierProductID\" value = \"$txtSupplierProductID\" size= \"20\" maxlength=\"50\">
         </td>
     </tr>

     <tr>
         <td align=\"right\">
             <b>Quantity Per Unit :&nbsp;</b>
         </td>
         <td align='left'>
           <input type=\"text\" name=\"txtQuantityPerUnit\" value = \"$txtQuantityPerUnit\" size= \"20\" maxlength=\"20\">
         </td>
     </tr>
	 
	 <tr>
         <td align=\"right\">
             <b>Cost Price&nbsp;(Ex&nbsp;Vat ".CURRENCY.")&nbsp;:&nbsp;</b>
         </td>
         <td align='left'>
           <input type=\"text\" name=\"txtCostPrice\" value = \"$txtCostPrice\" size= \"16\" maxlength=\"16\">
         </td>
     </tr>

	 
     <tr>
         <td align=\"right\">
             <b>";
			 	if($SHOP_TYPE == "Trade"){
					echo "Normal trade (Ex Vat ".CURRENCY.")";
				}else{
					echo "RRP(Inc Vat ".CURRENCY.")";
				}
echo "
			 &nbsp;:&nbsp;</b>
         </td>
         <td align='left'>
           <input type=\"text\" name=\"txtFullPrice\" value = \"$txtFullPrice\" size= \"16\" maxlength=\"16\">
         </td>
     </tr>
	 
     <tr>
         <td align=\"right\">
             <b>Our Price&nbsp;";
			 	if($SHOP_TYPE == "Trade"){
					echo "(Ex&nbsp;Vat ".CURRENCY.")";
				}else{
					echo "(Inc&nbsp;Vat ".CURRENCY.")";
				}
echo "
			 &nbsp;:&nbsp;</b>
         </td>
         <td align='left'>
           <input type=\"text\" name=\"txtUnitPrice\" value = \"$txtUnitPrice\" size= \"16\" maxlength=\"16\">
         </td>
     </tr>

     <tr align=\"right\">
         <td align=\"right\">
             <b>Vat Rate :&nbsp;</b>
         </td>
         <td align=\"left\">";
             CreateDropDown("cboVatRate", "SELECT * FROM tblVatRate ORDER BY 2", "", $cboVatRate);
echo "
             <a href='".ScreenURL("EnterVatRate")."' target='_blank'>+</a>
         </td>
     </tr>

     <tr>
         <td align=\"right\">
             <b>Units In Stock :&nbsp;</b>
         </td>
         <td align=\"left\">
           <input type=\"text\" name=\"txtUnitsInStock\" value = \"$txtUnitsInStock\" size= \"3\" maxlength=\"3\">
         </td>
     </tr>
<!-- 
     <tr>
         <td align=\"right\">
             <b>Units On Order :&nbsp;</b>
         </td>
         <td align=\"left\">
           <input type=\"text\" name=\"txtUnitsOnOrder\" value = \"$txtUnitsOnOrder\" size= \"2\" maxlength=\"2\">
         </td>
     </tr>

     <tr>
         <td align=\"right\">
             <b>Reorder Level :&nbsp;</b>
         </td>
         <td align=\"left\">
           <input type=\"text\" name=\"txtReorderLevel\" value = \"$txtReorderLevel\" size= \"2\" maxlength=\"2\">
         </td>
     </tr>
 -->
 
     <tr>
         <td align=\"right\">
             <b>Discontinued :</b>
		 </td>
         <td align=\"left\">
		 	<input type=\"checkbox\" name=\"chkDiscontinued\" value='1'";
			
			  if($chkDiscontinued == 1){
			  	echo " checked>";
			  }else{
			  	echo ">";
			  }
	echo "
         </td>
     </tr>
     <tr align=\"right\">
         <td align=\"right\">
             <b>Promotional Item :</b>
                 
		</td>
        <td align=\"left\">
			<input type=\"checkbox\" name=\"chkPromotionalItem\"  value='1'";
				 if($chkPromotionalItem == 1){
				  	echo " checked>";
				 }else{
				  	echo ">";
				 }
	echo "

		</td>
     </tr>
	 <tr>
		<td colspan='2'>
			<hr/>
		</td>
	 </tr>
     <tr>
         <td align='right' valign='middle'>
             <b>Upload/Replace Picture :&nbsp;</b>";
	?>
			 
			
			 
			 
	<?php 
	echo "
			 
		 </td>
         <td align=\"left\"  valign='middle'>
";
             CreateDropDown("cboUploadedPicture", "SELECT * FROM tblYesNo ORDER BY 2", "", $cboUploadedPicture);
?>
             <?php if($myrow["UploadedPicture"]){ ?><img src='./images/product/thumbz/<?php echo $myrow["UploadedPicture"]?>' border='0' alt='Item <?php echo $myrow["ID"]?>' width='100'><?php }?> 
<?php
			
echo "
			<br/><a href='" . ScreenURL("EnterProduct",array('ACTION'=>'actDeleteProductPicture','strPhoto'=>$myrow["UploadedPicture"],'intProductID'=>$myrow[0]) ) . "' target='_blank'>Delete Picture</a>

         </td>
     </tr>

	 <tr>
	 	<td align='center' colspan='2'>
			<input type=\"file\" name=\"txtUploadedPicture\" value = \"$txtUploadedPicture\" size= \"50\" maxlength=\"50\"></div>
		</td>
	</tr>

	<tr>
         <td align='left' colspan='2'>
			<hr/>
          </td>
     </tr>

     <tr>
         <td align=\"right\" colspan='2'>
             <input type='image' src='./images".SITE_SUFFIX."/$strButtonTitle.gif' alt='$strButtonTitle'>
         </td>
     </tr>
         </table>
     </form>
     </td>
 </tr>
";
?>
	<tr>
		<td>
			<?
  			if($intProductID)
  			{
			?>
			<table width='100%' border='1'>
				<tr>
					<td>
						<a href="<?php echo "javascript:;\" onMouseUp=\"MM_openBrWindow('".ScreenURL("EnterProductPictures",array('intProductID'=>$intProductID))."','Upload Pictures','toolbar=No,menubar=No,scrollbars=Yes,width=630,height=630')\" >"?>Upload more pictures</a>
						<?php
							include(MODULE."/action/actListJpgsInDir.php");
						?>
					</td>
				</tr>
			</table>
			<?php
			}
			?>		
		</td>
	</tr>
<?php
if($strStyleSheet == TRUE){
	echo "</table>";
}
?>
<script language="JavaScript">
<!--
function frmEnterProduct_onsubmit() 
{


     if(document.frmEnterProduct.txtProduct.value == "") {
         alert("Please enter Product Name");
         document.frmEnterProduct.txtProduct.focus();
         document.frmEnterProduct.txtProduct.select();
         return(false);
     }

     if(document.frmEnterProduct.txtDescription.value == "") {
         alert("Please enter Description");
         document.frmEnterProduct.txtDescription.focus();
         document.frmEnterProduct.txtDescription.select();
         return(false);
     }

     if(document.frmEnterProduct.txtQuantityPerUnit.value == "") {
         alert("Please enter Quantity Per Unit");
         document.frmEnterProduct.txtQuantityPerUnit.focus();
         document.frmEnterProduct.txtQuantityPerUnit.select();
         return(false);
     }

     if(document.frmEnterProduct.txtUnitPrice.value == "") {
         alert("Please enter Unit Retail Price (Including Vat)");
         document.frmEnterProduct.txtUnitPrice.focus();
         document.frmEnterProduct.txtUnitPrice.select();
         return(false);
     }

     if(document.frmEnterProduct.txtFullPrice.value == "") {
         alert("Please enter Recommended Retail Price (Including Vat)");
         document.frmEnterProduct.txtFullPrice.focus();
         document.frmEnterProduct.txtFullPrice.select();
         return(false);
     }
	 
	 if(document.frmEnterProduct.txtMetaTitle.value == "") {
         alert("Please enter Meta Title");
         document.frmEnterProduct.txtMetaTitle.focus();
         document.frmEnterProduct.txtMetaTitle.select();
         return(false);
     }

     if(document.frmEnterProduct.txtMetaDescription.value == "") {
         alert("Please enter Meta Description");
         document.frmEnterProduct.txtMetaDescription.focus();
         document.frmEnterProduct.txtMetaDescription.select();
         return(false);
     }

     if(document.frmEnterProduct.txtMetaKeyword.value == "") {
         alert("Please enter Meta Keyword");
         document.frmEnterProduct.txtMetaKeyword.focus();
         document.frmEnterProduct.txtMetaKeyword.select();
         return(false);
     }

}
// -->
</script>
